<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

// define OPENIDPATH so we can require php-openid scripts when necessary
if (!defined('OPENIDPATH'))
	define('OPENIDPATH', APPPATH.'libraries/php-openid/');
	
require_once OPENIDPATH.'Auth/OpenID/Consumer.php';
require_once OPENIDPATH.'Auth/OpenID/FileStore.php';
require_once OPENIDPATH.'Auth/OpenID/SReg.php';

if (!defined('OPENID_DATASTORE_PATH'))
	define('OPENID_DATASTORE_PATH', '/tmp/_bricabox_openid_store');

function create_consumer()
{
	create_datastore();
	$store		= new Auth_OpenID_FileStore(OPENID_DATASTORE_PATH);
	$consumer 	= new Auth_OpenID_Consumer($store);
	return $consumer;
}

function create_datastore()
{
	if (!file_exists(OPENID_DATASTORE_PATH))
		mkdir(OPENID_DATASTORE_PATH);
}

function build_openid_urls($token)
{
	$urls 				= array();
	$urls['trust_root'] = APP_ROOT_URL.'/'; // http://bricabox.com/
	$urls['redirect']	= APP_ROOT_URL.'/openid_complete.php?auth_token='.$token;
	return $urls;
}
?>